#include "Texture.h"

Texture::Texture(LPDIRECT3DDEVICE9 pd3dDevice)
{
	_pd3dDevice = pd3dDevice;
}

Texture::~Texture()
{
	if (_image != NULL) _image->Release();
}

bool Texture::LoadTexture(LPCSTR filename, D3DCOLOR transcolor)
{
	// standard Windows return value
	HRESULT result;

	// get width and height from image file
	result = D3DXGetImageInfoFromFile(filename, &_info);

	if (result != D3D_OK)
		return false;

	// create the new texture by loading a image file 
	result = D3DXCreateTextureFromFileEx(_pd3dDevice,
		filename,
		_info.Width,
		_info.Height,
		1,
		D3DPOOL_DEFAULT,
		D3DFMT_UNKNOWN,
		D3DPOOL_DEFAULT,
		D3DX_DEFAULT,
		D3DX_DEFAULT,
		transcolor,
		&_info,
		NULL,
		&_image);

	// make sure the image texture was loaded correctly
	if (result != D3D_OK)
		return false;

	if (_image != NULL)
	{
		_width = _info.Width;
		_height = _info.Height;
	}
	else
	{
		_width = _height = -1;
		return false;
	}

	return true;
}
